<template>
  <div class="demo-img" ref="imgWall">
    <div class="demo-img-wrapper">
      <img src="~@/assets/img/imgWall/1.jpg" />
      <img src="~@/assets/img/imgWall/2.jpg" />
      <img src="~@/assets/img/imgWall/3.jpg" />
      <img src="~@/assets/img/imgWall/4.jpg" />
      <img src="~@/assets/img/imgWall/5.jpg" />
      <img src="~@/assets/img/imgWall/6.jpg" />
      <img src="~@/assets/img/imgWall/7.jpg" />
      <img src="~@/assets/img/imgWall/8.jpg" />
    </div>
  </div>
</template>

<script>
export default {
  mounted() {
    this.bindMouse()
  },
  beforeRouteLeave(to, from, next) {
    this.$refs.imgWall.onmousemove = ''
    next()
  },
  methods: {
    bindMouse() {
      this.$refs.imgWall.onmousemove = function (e) {
        this.style.perspectiveOrigin = '' + e.pageX + 'px ' + e.pageY + 'px'
      }
    }
  }
}
</script>

<style lang="scss">
@keyframes round {
  0% {
    transform: translate(-50%, -50%) rotatey(0deg);
  }

  100% {
    transform: translate(-50%, -50%) rotatey(360deg);
  }
}

.demo-img {
  position: relative;
  height: 100vh;

  perspective: 3000px;
  transform-style: preserve-3d;
  /* 当设置了其中一个时，这个就作为下面left，top的参照物了。他没高度。所以要传承一下 */

  .demo-img-wrapper {
    position: absolute;
    left: calc(50%);
    top: calc(50%);
    //   width: 300px;
    height: 300px;
    // height: 100vh;
    width: 300px;
    transform: translate(-50%, -50%);
    transform-style: preserve-3d;
    /* 需要设置在  直接父元素 */
    animation: round 15s linear infinite;

    img {
      position: absolute;
      width: 400px;
      /*backface-visibility:hidden;*/
    }

    img:nth-of-type(1) {
      transform: rotatey(45deg) translatez(100px);
    }

    img:nth-of-type(2) {
      transform: rotatey(90deg) translatez(500px);
    }

    img:nth-of-type(3) {
      transform: rotatey(135deg) translatez(300px);
    }

    img:nth-of-type(4) {
      transform: rotatey(180deg) translatez(500px);
    }

    img:nth-of-type(5) {
      transform: rotatey(225deg) translatez(200px);
    }

    img:nth-of-type(6) {
      transform: rotatey(270deg) translatez(500px);
    }

    img:nth-of-type(7) {
      transform: rotatey(315deg) translatez(800px);
    }

    img:nth-of-type(8) {
      transform: rotatey(360deg) translatez(500px);
    }
  }
}
</style>
